package com.leizhou.ccontroller;

import com.leizhou.pojo.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 第二种方式: 注入属性
 * @Value： 只能注入(基本数据类型 + String)
 */
@RestController
// @ConfigurationProperties(prefix = "my")
public class PropController02{
    @Value("${my.host}")
    private String host;
    @Value("${my.port}")
    private int port;
    private User user;
    private String[] address;
    private List<User> users;

    @GetMapping("/test2")
    public String test2() {
        System.out.println("======test2=======");
        System.out.println("host = " + host);
        System.out.println("port = " + port);
        System.out.println("user = " + user);
        System.out.println("address = " + Arrays.toString(address));
        System.out.println("users = " + users);
        return "test2方法，访问成功！";
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setAddress(String[] address) {
        this.address = address;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }
}